package nl.uva.science.pico.stacklanguage;

public class Factory {
  private aterm.pure.PureFactory factory;


  private aterm.AFun fun_InstrList_InstrList;
  private aterm.ATerm pattern_InstrList_InstrList;

  private aterm.AFun fun_LabelInstr_LabelInstr;
  private aterm.ATerm pattern_LabelInstr_LabelInstr;

  private aterm.AFun fun_Instr_Nat;
  private aterm.ATerm pattern_Instr_Nat;
  private aterm.AFun fun_Instr_Str;
  private aterm.ATerm pattern_Instr_Str;
  private aterm.AFun fun_Instr_Minus;
  private aterm.ATerm pattern_Instr_Minus;
  private aterm.AFun fun_Instr_Add;
  private aterm.ATerm pattern_Instr_Add;
  private aterm.AFun fun_Instr_Mult;
  private aterm.ATerm pattern_Instr_Mult;
  private aterm.AFun fun_Instr_Div;
  private aterm.ATerm pattern_Instr_Div;
  private aterm.AFun fun_Instr_Concat;
  private aterm.ATerm pattern_Instr_Concat;
  private aterm.AFun fun_Instr_Ifequal;
  private aterm.ATerm pattern_Instr_Ifequal;
  private aterm.AFun fun_Instr_Iflessequal;
  private aterm.ATerm pattern_Instr_Iflessequal;
  private aterm.AFun fun_Instr_Ifless;
  private aterm.ATerm pattern_Instr_Ifless;
  private aterm.AFun fun_Instr_Goto;
  private aterm.ATerm pattern_Instr_Goto;
  private aterm.AFun fun_Instr_Pop;
  private aterm.ATerm pattern_Instr_Pop;
  private aterm.AFun fun_Instr_Count;
  private aterm.ATerm pattern_Instr_Count;
  private aterm.AFun fun_Instr_Store;
  private aterm.ATerm pattern_Instr_Store;
  private aterm.AFun fun_Instr_Load;
  private aterm.ATerm pattern_Instr_Load;
  private aterm.AFun fun_Instr_Skip;
  private aterm.ATerm pattern_Instr_Skip;
  private aterm.AFun fun_Instr_Stop;
  private aterm.ATerm pattern_Instr_Stop;


  private nl.uva.science.pico.stacklanguage.types.LabelInstrList empty_LabelInstrList;

  private Factory(aterm.pure.PureFactory factory) {
    this.factory = factory;
  }

  private static Factory instance = null;

  public synchronized static Factory getInstance(aterm.pure.PureFactory factory) {
    if (instance == null) {
        instance = new Factory(factory);
        instance.initialize();
    }
    if (instance.factory != factory) {
        throw new RuntimeException("Don't create two Factory factories with differents PureFactory ");
    }
    return instance;
  }

  public aterm.pure.PureFactory getPureFactory() {
    return factory;
  }

  private void initialize() {

    pattern_InstrList_InstrList = factory.parse("InstrList(<term>)");
    fun_InstrList_InstrList = factory.makeAFun("_Instr-List_InstrList", 1, false);

    pattern_LabelInstr_LabelInstr = factory.parse("LabelInstr(<int>,<term>)");
    fun_LabelInstr_LabelInstr = factory.makeAFun("_Label-Instr_LabelInstr", 2, false);

    pattern_Instr_Nat = factory.parse("nat(<int>)");
    fun_Instr_Nat = factory.makeAFun("_Instr_nat", 1, false);

    pattern_Instr_Str = factory.parse("str(<str>)");
    fun_Instr_Str = factory.makeAFun("_Instr_str", 1, false);

    pattern_Instr_Minus = factory.parse("minus");
    fun_Instr_Minus = factory.makeAFun("_Instr_minus", 0, false);

    pattern_Instr_Add = factory.parse("add");
    fun_Instr_Add = factory.makeAFun("_Instr_add", 0, false);

    pattern_Instr_Mult = factory.parse("mult");
    fun_Instr_Mult = factory.makeAFun("_Instr_mult", 0, false);

    pattern_Instr_Div = factory.parse("div");
    fun_Instr_Div = factory.makeAFun("_Instr_div", 0, false);

    pattern_Instr_Concat = factory.parse("concat");
    fun_Instr_Concat = factory.makeAFun("_Instr_concat", 0, false);

    pattern_Instr_Ifequal = factory.parse("ifequal");
    fun_Instr_Ifequal = factory.makeAFun("_Instr_ifequal", 0, false);

    pattern_Instr_Iflessequal = factory.parse("iflessequal");
    fun_Instr_Iflessequal = factory.makeAFun("_Instr_iflessequal", 0, false);

    pattern_Instr_Ifless = factory.parse("ifless");
    fun_Instr_Ifless = factory.makeAFun("_Instr_ifless", 0, false);

    pattern_Instr_Goto = factory.parse("goto");
    fun_Instr_Goto = factory.makeAFun("_Instr_goto", 0, false);

    pattern_Instr_Pop = factory.parse("pop");
    fun_Instr_Pop = factory.makeAFun("_Instr_pop", 0, false);

    pattern_Instr_Count = factory.parse("count");
    fun_Instr_Count = factory.makeAFun("_Instr_count", 0, false);

    pattern_Instr_Store = factory.parse("store");
    fun_Instr_Store = factory.makeAFun("_Instr_store", 0, false);

    pattern_Instr_Load = factory.parse("load");
    fun_Instr_Load = factory.makeAFun("_Instr_load", 0, false);

    pattern_Instr_Skip = factory.parse("skip");
    fun_Instr_Skip = factory.makeAFun("_Instr_skip", 0, false);

    pattern_Instr_Stop = factory.parse("stop");
    fun_Instr_Stop = factory.makeAFun("_Instr_stop", 0, false);

    empty_LabelInstrList = (nl.uva.science.pico.stacklanguage.types.LabelInstrList) factory.build(new nl.uva.science.pico.stacklanguage.types.LabelInstrList(this, factory.getEmpty(), null, null));
  }

/*genAlternativeMethods*/
  public nl.uva.science.pico.stacklanguage.types.instrlist.InstrList makeInstrList_InstrList(aterm.AFun fun, aterm.ATerm[] args, aterm.ATermList annos) {
    return (nl.uva.science.pico.stacklanguage.types.instrlist.InstrList) factory.build( new nl.uva.science.pico.stacklanguage.types.instrlist.InstrList(this, annos, fun, args));
  }

  public nl.uva.science.pico.stacklanguage.types.instrlist.InstrList makeInstrList_InstrList(nl.uva.science.pico.stacklanguage.types.LabelInstrList _list) {
    aterm.ATerm[] args = new aterm.ATerm[] {_list};
    return makeInstrList_InstrList(fun_InstrList_InstrList, args, factory.getEmpty());
  }

  protected nl.uva.science.pico.stacklanguage.types.InstrList InstrList_InstrListFromTerm(aterm.ATerm trm) {
    java.util.List<Object> children = trm.match(pattern_InstrList_InstrList);

    if (children != null) {
      return makeInstrList_InstrList(
        LabelInstrListFromTerm((aterm.ATerm) children.get(0))
      );
    }
    return null;
  }

  public aterm.ATerm toTerm(nl.uva.science.pico.stacklanguage.types.instrlist.InstrList arg) {
    java.util.List<Object> args = new java.util.LinkedList<Object>();
    args.add(arg.getList().toTerm());
    return factory.make(pattern_InstrList_InstrList, args);
  }

  public nl.uva.science.pico.stacklanguage.types.labelinstr.LabelInstr makeLabelInstr_LabelInstr(aterm.AFun fun, aterm.ATerm[] args, aterm.ATermList annos) {
    return (nl.uva.science.pico.stacklanguage.types.labelinstr.LabelInstr) factory.build( new nl.uva.science.pico.stacklanguage.types.labelinstr.LabelInstr(this, annos, fun, args));
  }

  public nl.uva.science.pico.stacklanguage.types.labelinstr.LabelInstr makeLabelInstr_LabelInstr(int _NatCon, nl.uva.science.pico.stacklanguage.types.Instr _Instr) {
    aterm.ATerm[] args = new aterm.ATerm[] {factory.makeInt(_NatCon), _Instr};
    return makeLabelInstr_LabelInstr(fun_LabelInstr_LabelInstr, args, factory.getEmpty());
  }

  protected nl.uva.science.pico.stacklanguage.types.LabelInstr LabelInstr_LabelInstrFromTerm(aterm.ATerm trm) {
    java.util.List<Object> children = trm.match(pattern_LabelInstr_LabelInstr);

    if (children != null) {
      return makeLabelInstr_LabelInstr(
        ((Integer) children.get(0)).intValue(),
        InstrFromTerm((aterm.ATerm) children.get(1))
      );
    }
    return null;
  }

  public aterm.ATerm toTerm(nl.uva.science.pico.stacklanguage.types.labelinstr.LabelInstr arg) {
    java.util.List<Object> args = new java.util.LinkedList<Object>();
    args.add(new Integer(arg.getNatCon()));
    args.add(arg.getInstr().toTerm());
    return factory.make(pattern_LabelInstr_LabelInstr, args);
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Nat makeInstr_Nat(aterm.AFun fun, aterm.ATerm[] args, aterm.ATermList annos) {
    return (nl.uva.science.pico.stacklanguage.types.instr.Nat) factory.build( new nl.uva.science.pico.stacklanguage.types.instr.Nat(this, annos, fun, args));
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Nat makeInstr_Nat(int _NatCon) {
    aterm.ATerm[] args = new aterm.ATerm[] {factory.makeInt(_NatCon)};
    return makeInstr_Nat(fun_Instr_Nat, args, factory.getEmpty());
  }

  protected nl.uva.science.pico.stacklanguage.types.Instr Instr_NatFromTerm(aterm.ATerm trm) {
    java.util.List<Object> children = trm.match(pattern_Instr_Nat);

    if (children != null) {
      return makeInstr_Nat(
        ((Integer) children.get(0)).intValue()
      );
    }
    return null;
  }

  public aterm.ATerm toTerm(nl.uva.science.pico.stacklanguage.types.instr.Nat arg) {
    java.util.List<Object> args = new java.util.LinkedList<Object>();
    args.add(new Integer(arg.getNatCon()));
    return factory.make(pattern_Instr_Nat, args);
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Str makeInstr_Str(aterm.AFun fun, aterm.ATerm[] args, aterm.ATermList annos) {
    return (nl.uva.science.pico.stacklanguage.types.instr.Str) factory.build( new nl.uva.science.pico.stacklanguage.types.instr.Str(this, annos, fun, args));
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Str makeInstr_Str(String _StrCon) {
    aterm.ATerm[] args = new aterm.ATerm[] {factory.makeAppl(factory.makeAFun(_StrCon, 0, true))};
    return makeInstr_Str(fun_Instr_Str, args, factory.getEmpty());
  }

  protected nl.uva.science.pico.stacklanguage.types.Instr Instr_StrFromTerm(aterm.ATerm trm) {
    java.util.List<Object> children = trm.match(pattern_Instr_Str);

    if (children != null) {
      return makeInstr_Str(
        (String) children.get(0)
      );
    }
    return null;
  }

  public aterm.ATerm toTerm(nl.uva.science.pico.stacklanguage.types.instr.Str arg) {
    java.util.List<Object> args = new java.util.LinkedList<Object>();
    args.add(arg.getStrCon());
    return factory.make(pattern_Instr_Str, args);
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Minus makeInstr_Minus(aterm.AFun fun, aterm.ATerm[] args, aterm.ATermList annos) {
    return (nl.uva.science.pico.stacklanguage.types.instr.Minus) factory.build( new nl.uva.science.pico.stacklanguage.types.instr.Minus(this, annos, fun, args));
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Minus makeInstr_Minus() {
    aterm.ATerm[] args = new aterm.ATerm[] {};
    return makeInstr_Minus(fun_Instr_Minus, args, factory.getEmpty());
  }

  protected nl.uva.science.pico.stacklanguage.types.Instr Instr_MinusFromTerm(aterm.ATerm trm) {
    java.util.List<Object> children = trm.match(pattern_Instr_Minus);

    if (children != null) {
      return makeInstr_Minus(
      );
    }
    return null;
  }

  public aterm.ATerm toTerm(nl.uva.science.pico.stacklanguage.types.instr.Minus arg) {
    java.util.List<Object> args = new java.util.LinkedList<Object>();
    return factory.make(pattern_Instr_Minus, args);
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Add makeInstr_Add(aterm.AFun fun, aterm.ATerm[] args, aterm.ATermList annos) {
    return (nl.uva.science.pico.stacklanguage.types.instr.Add) factory.build( new nl.uva.science.pico.stacklanguage.types.instr.Add(this, annos, fun, args));
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Add makeInstr_Add() {
    aterm.ATerm[] args = new aterm.ATerm[] {};
    return makeInstr_Add(fun_Instr_Add, args, factory.getEmpty());
  }

  protected nl.uva.science.pico.stacklanguage.types.Instr Instr_AddFromTerm(aterm.ATerm trm) {
    java.util.List<Object> children = trm.match(pattern_Instr_Add);

    if (children != null) {
      return makeInstr_Add(
      );
    }
    return null;
  }

  public aterm.ATerm toTerm(nl.uva.science.pico.stacklanguage.types.instr.Add arg) {
    java.util.List<Object> args = new java.util.LinkedList<Object>();
    return factory.make(pattern_Instr_Add, args);
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Mult makeInstr_Mult(aterm.AFun fun, aterm.ATerm[] args, aterm.ATermList annos) {
    return (nl.uva.science.pico.stacklanguage.types.instr.Mult) factory.build( new nl.uva.science.pico.stacklanguage.types.instr.Mult(this, annos, fun, args));
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Mult makeInstr_Mult() {
    aterm.ATerm[] args = new aterm.ATerm[] {};
    return makeInstr_Mult(fun_Instr_Mult, args, factory.getEmpty());
  }

  protected nl.uva.science.pico.stacklanguage.types.Instr Instr_MultFromTerm(aterm.ATerm trm) {
    java.util.List<Object> children = trm.match(pattern_Instr_Mult);

    if (children != null) {
      return makeInstr_Mult(
      );
    }
    return null;
  }

  public aterm.ATerm toTerm(nl.uva.science.pico.stacklanguage.types.instr.Mult arg) {
    java.util.List<Object> args = new java.util.LinkedList<Object>();
    return factory.make(pattern_Instr_Mult, args);
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Div makeInstr_Div(aterm.AFun fun, aterm.ATerm[] args, aterm.ATermList annos) {
    return (nl.uva.science.pico.stacklanguage.types.instr.Div) factory.build( new nl.uva.science.pico.stacklanguage.types.instr.Div(this, annos, fun, args));
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Div makeInstr_Div() {
    aterm.ATerm[] args = new aterm.ATerm[] {};
    return makeInstr_Div(fun_Instr_Div, args, factory.getEmpty());
  }

  protected nl.uva.science.pico.stacklanguage.types.Instr Instr_DivFromTerm(aterm.ATerm trm) {
    java.util.List<Object> children = trm.match(pattern_Instr_Div);

    if (children != null) {
      return makeInstr_Div(
      );
    }
    return null;
  }

  public aterm.ATerm toTerm(nl.uva.science.pico.stacklanguage.types.instr.Div arg) {
    java.util.List<Object> args = new java.util.LinkedList<Object>();
    return factory.make(pattern_Instr_Div, args);
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Concat makeInstr_Concat(aterm.AFun fun, aterm.ATerm[] args, aterm.ATermList annos) {
    return (nl.uva.science.pico.stacklanguage.types.instr.Concat) factory.build( new nl.uva.science.pico.stacklanguage.types.instr.Concat(this, annos, fun, args));
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Concat makeInstr_Concat() {
    aterm.ATerm[] args = new aterm.ATerm[] {};
    return makeInstr_Concat(fun_Instr_Concat, args, factory.getEmpty());
  }

  protected nl.uva.science.pico.stacklanguage.types.Instr Instr_ConcatFromTerm(aterm.ATerm trm) {
    java.util.List<Object> children = trm.match(pattern_Instr_Concat);

    if (children != null) {
      return makeInstr_Concat(
      );
    }
    return null;
  }

  public aterm.ATerm toTerm(nl.uva.science.pico.stacklanguage.types.instr.Concat arg) {
    java.util.List<Object> args = new java.util.LinkedList<Object>();
    return factory.make(pattern_Instr_Concat, args);
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Ifequal makeInstr_Ifequal(aterm.AFun fun, aterm.ATerm[] args, aterm.ATermList annos) {
    return (nl.uva.science.pico.stacklanguage.types.instr.Ifequal) factory.build( new nl.uva.science.pico.stacklanguage.types.instr.Ifequal(this, annos, fun, args));
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Ifequal makeInstr_Ifequal() {
    aterm.ATerm[] args = new aterm.ATerm[] {};
    return makeInstr_Ifequal(fun_Instr_Ifequal, args, factory.getEmpty());
  }

  protected nl.uva.science.pico.stacklanguage.types.Instr Instr_IfequalFromTerm(aterm.ATerm trm) {
    java.util.List<Object> children = trm.match(pattern_Instr_Ifequal);

    if (children != null) {
      return makeInstr_Ifequal(
      );
    }
    return null;
  }

  public aterm.ATerm toTerm(nl.uva.science.pico.stacklanguage.types.instr.Ifequal arg) {
    java.util.List<Object> args = new java.util.LinkedList<Object>();
    return factory.make(pattern_Instr_Ifequal, args);
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Iflessequal makeInstr_Iflessequal(aterm.AFun fun, aterm.ATerm[] args, aterm.ATermList annos) {
    return (nl.uva.science.pico.stacklanguage.types.instr.Iflessequal) factory.build( new nl.uva.science.pico.stacklanguage.types.instr.Iflessequal(this, annos, fun, args));
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Iflessequal makeInstr_Iflessequal() {
    aterm.ATerm[] args = new aterm.ATerm[] {};
    return makeInstr_Iflessequal(fun_Instr_Iflessequal, args, factory.getEmpty());
  }

  protected nl.uva.science.pico.stacklanguage.types.Instr Instr_IflessequalFromTerm(aterm.ATerm trm) {
    java.util.List<Object> children = trm.match(pattern_Instr_Iflessequal);

    if (children != null) {
      return makeInstr_Iflessequal(
      );
    }
    return null;
  }

  public aterm.ATerm toTerm(nl.uva.science.pico.stacklanguage.types.instr.Iflessequal arg) {
    java.util.List<Object> args = new java.util.LinkedList<Object>();
    return factory.make(pattern_Instr_Iflessequal, args);
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Ifless makeInstr_Ifless(aterm.AFun fun, aterm.ATerm[] args, aterm.ATermList annos) {
    return (nl.uva.science.pico.stacklanguage.types.instr.Ifless) factory.build( new nl.uva.science.pico.stacklanguage.types.instr.Ifless(this, annos, fun, args));
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Ifless makeInstr_Ifless() {
    aterm.ATerm[] args = new aterm.ATerm[] {};
    return makeInstr_Ifless(fun_Instr_Ifless, args, factory.getEmpty());
  }

  protected nl.uva.science.pico.stacklanguage.types.Instr Instr_IflessFromTerm(aterm.ATerm trm) {
    java.util.List<Object> children = trm.match(pattern_Instr_Ifless);

    if (children != null) {
      return makeInstr_Ifless(
      );
    }
    return null;
  }

  public aterm.ATerm toTerm(nl.uva.science.pico.stacklanguage.types.instr.Ifless arg) {
    java.util.List<Object> args = new java.util.LinkedList<Object>();
    return factory.make(pattern_Instr_Ifless, args);
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Goto makeInstr_Goto(aterm.AFun fun, aterm.ATerm[] args, aterm.ATermList annos) {
    return (nl.uva.science.pico.stacklanguage.types.instr.Goto) factory.build( new nl.uva.science.pico.stacklanguage.types.instr.Goto(this, annos, fun, args));
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Goto makeInstr_Goto() {
    aterm.ATerm[] args = new aterm.ATerm[] {};
    return makeInstr_Goto(fun_Instr_Goto, args, factory.getEmpty());
  }

  protected nl.uva.science.pico.stacklanguage.types.Instr Instr_GotoFromTerm(aterm.ATerm trm) {
    java.util.List<Object> children = trm.match(pattern_Instr_Goto);

    if (children != null) {
      return makeInstr_Goto(
      );
    }
    return null;
  }

  public aterm.ATerm toTerm(nl.uva.science.pico.stacklanguage.types.instr.Goto arg) {
    java.util.List<Object> args = new java.util.LinkedList<Object>();
    return factory.make(pattern_Instr_Goto, args);
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Pop makeInstr_Pop(aterm.AFun fun, aterm.ATerm[] args, aterm.ATermList annos) {
    return (nl.uva.science.pico.stacklanguage.types.instr.Pop) factory.build( new nl.uva.science.pico.stacklanguage.types.instr.Pop(this, annos, fun, args));
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Pop makeInstr_Pop() {
    aterm.ATerm[] args = new aterm.ATerm[] {};
    return makeInstr_Pop(fun_Instr_Pop, args, factory.getEmpty());
  }

  protected nl.uva.science.pico.stacklanguage.types.Instr Instr_PopFromTerm(aterm.ATerm trm) {
    java.util.List<Object> children = trm.match(pattern_Instr_Pop);

    if (children != null) {
      return makeInstr_Pop(
      );
    }
    return null;
  }

  public aterm.ATerm toTerm(nl.uva.science.pico.stacklanguage.types.instr.Pop arg) {
    java.util.List<Object> args = new java.util.LinkedList<Object>();
    return factory.make(pattern_Instr_Pop, args);
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Count makeInstr_Count(aterm.AFun fun, aterm.ATerm[] args, aterm.ATermList annos) {
    return (nl.uva.science.pico.stacklanguage.types.instr.Count) factory.build( new nl.uva.science.pico.stacklanguage.types.instr.Count(this, annos, fun, args));
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Count makeInstr_Count() {
    aterm.ATerm[] args = new aterm.ATerm[] {};
    return makeInstr_Count(fun_Instr_Count, args, factory.getEmpty());
  }

  protected nl.uva.science.pico.stacklanguage.types.Instr Instr_CountFromTerm(aterm.ATerm trm) {
    java.util.List<Object> children = trm.match(pattern_Instr_Count);

    if (children != null) {
      return makeInstr_Count(
      );
    }
    return null;
  }

  public aterm.ATerm toTerm(nl.uva.science.pico.stacklanguage.types.instr.Count arg) {
    java.util.List<Object> args = new java.util.LinkedList<Object>();
    return factory.make(pattern_Instr_Count, args);
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Store makeInstr_Store(aterm.AFun fun, aterm.ATerm[] args, aterm.ATermList annos) {
    return (nl.uva.science.pico.stacklanguage.types.instr.Store) factory.build( new nl.uva.science.pico.stacklanguage.types.instr.Store(this, annos, fun, args));
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Store makeInstr_Store() {
    aterm.ATerm[] args = new aterm.ATerm[] {};
    return makeInstr_Store(fun_Instr_Store, args, factory.getEmpty());
  }

  protected nl.uva.science.pico.stacklanguage.types.Instr Instr_StoreFromTerm(aterm.ATerm trm) {
    java.util.List<Object> children = trm.match(pattern_Instr_Store);

    if (children != null) {
      return makeInstr_Store(
      );
    }
    return null;
  }

  public aterm.ATerm toTerm(nl.uva.science.pico.stacklanguage.types.instr.Store arg) {
    java.util.List<Object> args = new java.util.LinkedList<Object>();
    return factory.make(pattern_Instr_Store, args);
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Load makeInstr_Load(aterm.AFun fun, aterm.ATerm[] args, aterm.ATermList annos) {
    return (nl.uva.science.pico.stacklanguage.types.instr.Load) factory.build( new nl.uva.science.pico.stacklanguage.types.instr.Load(this, annos, fun, args));
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Load makeInstr_Load() {
    aterm.ATerm[] args = new aterm.ATerm[] {};
    return makeInstr_Load(fun_Instr_Load, args, factory.getEmpty());
  }

  protected nl.uva.science.pico.stacklanguage.types.Instr Instr_LoadFromTerm(aterm.ATerm trm) {
    java.util.List<Object> children = trm.match(pattern_Instr_Load);

    if (children != null) {
      return makeInstr_Load(
      );
    }
    return null;
  }

  public aterm.ATerm toTerm(nl.uva.science.pico.stacklanguage.types.instr.Load arg) {
    java.util.List<Object> args = new java.util.LinkedList<Object>();
    return factory.make(pattern_Instr_Load, args);
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Skip makeInstr_Skip(aterm.AFun fun, aterm.ATerm[] args, aterm.ATermList annos) {
    return (nl.uva.science.pico.stacklanguage.types.instr.Skip) factory.build( new nl.uva.science.pico.stacklanguage.types.instr.Skip(this, annos, fun, args));
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Skip makeInstr_Skip() {
    aterm.ATerm[] args = new aterm.ATerm[] {};
    return makeInstr_Skip(fun_Instr_Skip, args, factory.getEmpty());
  }

  protected nl.uva.science.pico.stacklanguage.types.Instr Instr_SkipFromTerm(aterm.ATerm trm) {
    java.util.List<Object> children = trm.match(pattern_Instr_Skip);

    if (children != null) {
      return makeInstr_Skip(
      );
    }
    return null;
  }

  public aterm.ATerm toTerm(nl.uva.science.pico.stacklanguage.types.instr.Skip arg) {
    java.util.List<Object> args = new java.util.LinkedList<Object>();
    return factory.make(pattern_Instr_Skip, args);
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Stop makeInstr_Stop(aterm.AFun fun, aterm.ATerm[] args, aterm.ATermList annos) {
    return (nl.uva.science.pico.stacklanguage.types.instr.Stop) factory.build( new nl.uva.science.pico.stacklanguage.types.instr.Stop(this, annos, fun, args));
  }

  public nl.uva.science.pico.stacklanguage.types.instr.Stop makeInstr_Stop() {
    aterm.ATerm[] args = new aterm.ATerm[] {};
    return makeInstr_Stop(fun_Instr_Stop, args, factory.getEmpty());
  }

  protected nl.uva.science.pico.stacklanguage.types.Instr Instr_StopFromTerm(aterm.ATerm trm) {
    java.util.List<Object> children = trm.match(pattern_Instr_Stop);

    if (children != null) {
      return makeInstr_Stop(
      );
    }
    return null;
  }

  public aterm.ATerm toTerm(nl.uva.science.pico.stacklanguage.types.instr.Stop arg) {
    java.util.List<Object> args = new java.util.LinkedList<Object>();
    return factory.make(pattern_Instr_Stop, args);
  }

/*genMakeLists*/
  public nl.uva.science.pico.stacklanguage.types.LabelInstrList makeLabelInstrList() {
    return empty_LabelInstrList;
  }

  public nl.uva.science.pico.stacklanguage.types.LabelInstrList makeLabelInstrList(nl.uva.science.pico.stacklanguage.types.LabelInstr elem) {
    return makeLabelInstrList(elem, empty_LabelInstrList);
  }

  public nl.uva.science.pico.stacklanguage.types.LabelInstrList makeLabelInstrList(nl.uva.science.pico.stacklanguage.types.LabelInstr head, nl.uva.science.pico.stacklanguage.types.LabelInstrList tail) {
    return makeLabelInstrList(head, tail, factory.getEmpty());
  }

  public nl.uva.science.pico.stacklanguage.types.LabelInstrList makeLabelInstrList(aterm.ATerm head, aterm.ATermList tail, aterm.ATermList annos) {
      return (nl.uva.science.pico.stacklanguage.types.LabelInstrList) factory.build(new nl.uva.science.pico.stacklanguage.types.LabelInstrList(this, annos, head, tail));
  }

  public nl.uva.science.pico.stacklanguage.types.LabelInstrList makeLabelInstrList(nl.uva.science.pico.stacklanguage.types.LabelInstr elem0, nl.uva.science.pico.stacklanguage.types.LabelInstr elem1) {
    return makeLabelInstrList(elem0, makeLabelInstrList(elem1));
  }

  public nl.uva.science.pico.stacklanguage.types.LabelInstrList makeLabelInstrList(nl.uva.science.pico.stacklanguage.types.LabelInstr elem0, nl.uva.science.pico.stacklanguage.types.LabelInstr elem1, nl.uva.science.pico.stacklanguage.types.LabelInstr elem2) {
    return makeLabelInstrList(elem0, makeLabelInstrList(elem1, elem2));
  }

  public nl.uva.science.pico.stacklanguage.types.LabelInstrList makeLabelInstrList(nl.uva.science.pico.stacklanguage.types.LabelInstr elem0, nl.uva.science.pico.stacklanguage.types.LabelInstr elem1, nl.uva.science.pico.stacklanguage.types.LabelInstr elem2, nl.uva.science.pico.stacklanguage.types.LabelInstr elem3) {
    return makeLabelInstrList(elem0, makeLabelInstrList(elem1, elem2, elem3));
  }

  public nl.uva.science.pico.stacklanguage.types.LabelInstrList makeLabelInstrList(nl.uva.science.pico.stacklanguage.types.LabelInstr elem0, nl.uva.science.pico.stacklanguage.types.LabelInstr elem1, nl.uva.science.pico.stacklanguage.types.LabelInstr elem2, nl.uva.science.pico.stacklanguage.types.LabelInstr elem3, nl.uva.science.pico.stacklanguage.types.LabelInstr elem4) {
    return makeLabelInstrList(elem0, makeLabelInstrList(elem1, elem2, elem3, elem4));
  }

  public nl.uva.science.pico.stacklanguage.types.LabelInstrList makeLabelInstrList(nl.uva.science.pico.stacklanguage.types.LabelInstr elem0, nl.uva.science.pico.stacklanguage.types.LabelInstr elem1, nl.uva.science.pico.stacklanguage.types.LabelInstr elem2, nl.uva.science.pico.stacklanguage.types.LabelInstr elem3, nl.uva.science.pico.stacklanguage.types.LabelInstr elem4, nl.uva.science.pico.stacklanguage.types.LabelInstr elem5) {
    return makeLabelInstrList(elem0, makeLabelInstrList(elem1, elem2, elem3, elem4, elem5));
  }

  public nl.uva.science.pico.stacklanguage.types.LabelInstrList reverse(nl.uva.science.pico.stacklanguage.types.LabelInstrList arg) {
    nl.uva.science.pico.stacklanguage.types.LabelInstrList reversed = makeLabelInstrList();
    while (!arg.isEmpty()) {
      reversed = makeLabelInstrList(arg.getHead(), reversed);
      arg = arg.getTail();
    }
    return reversed;
  }

  public nl.uva.science.pico.stacklanguage.types.LabelInstrList concat(nl.uva.science.pico.stacklanguage.types.LabelInstrList arg0, nl.uva.science.pico.stacklanguage.types.LabelInstrList arg1) {
    nl.uva.science.pico.stacklanguage.types.LabelInstrList result = arg1;

    for (nl.uva.science.pico.stacklanguage.types.LabelInstrList list = reverse(arg0); !list.isEmpty(); list = list.getTail()) {
      result = makeLabelInstrList(list.getHead(), result);
    }

    return result;
  }

  public nl.uva.science.pico.stacklanguage.types.LabelInstrList append(nl.uva.science.pico.stacklanguage.types.LabelInstrList list, nl.uva.science.pico.stacklanguage.types.LabelInstr elem) {
    return concat(list, makeLabelInstrList(elem));
  }

/*genTypeFromTermMethods*/
  public nl.uva.science.pico.stacklanguage.types.InstrList InstrListFromTerm(aterm.ATerm trm) {
    nl.uva.science.pico.stacklanguage.types.InstrList tmp;
    tmp = InstrList_InstrListFromTerm(trm);
    if (tmp != null) {
      return tmp;
    }

    throw new IllegalArgumentException("This is not a InstrList: " + trm);
  }

  public nl.uva.science.pico.stacklanguage.types.LabelInstr LabelInstrFromTerm(aterm.ATerm trm) {
    nl.uva.science.pico.stacklanguage.types.LabelInstr tmp;
    tmp = LabelInstr_LabelInstrFromTerm(trm);
    if (tmp != null) {
      return tmp;
    }

    throw new IllegalArgumentException("This is not a LabelInstr: " + trm);
  }

  public nl.uva.science.pico.stacklanguage.types.Instr InstrFromTerm(aterm.ATerm trm) {
    nl.uva.science.pico.stacklanguage.types.Instr tmp;
    tmp = Instr_NatFromTerm(trm);
    if (tmp != null) {
      return tmp;
    }

    tmp = Instr_StrFromTerm(trm);
    if (tmp != null) {
      return tmp;
    }

    tmp = Instr_MinusFromTerm(trm);
    if (tmp != null) {
      return tmp;
    }

    tmp = Instr_AddFromTerm(trm);
    if (tmp != null) {
      return tmp;
    }

    tmp = Instr_MultFromTerm(trm);
    if (tmp != null) {
      return tmp;
    }

    tmp = Instr_DivFromTerm(trm);
    if (tmp != null) {
      return tmp;
    }

    tmp = Instr_ConcatFromTerm(trm);
    if (tmp != null) {
      return tmp;
    }

    tmp = Instr_IfequalFromTerm(trm);
    if (tmp != null) {
      return tmp;
    }

    tmp = Instr_IflessequalFromTerm(trm);
    if (tmp != null) {
      return tmp;
    }

    tmp = Instr_IflessFromTerm(trm);
    if (tmp != null) {
      return tmp;
    }

    tmp = Instr_GotoFromTerm(trm);
    if (tmp != null) {
      return tmp;
    }

    tmp = Instr_PopFromTerm(trm);
    if (tmp != null) {
      return tmp;
    }

    tmp = Instr_CountFromTerm(trm);
    if (tmp != null) {
      return tmp;
    }

    tmp = Instr_StoreFromTerm(trm);
    if (tmp != null) {
      return tmp;
    }

    tmp = Instr_LoadFromTerm(trm);
    if (tmp != null) {
      return tmp;
    }

    tmp = Instr_SkipFromTerm(trm);
    if (tmp != null) {
      return tmp;
    }

    tmp = Instr_StopFromTerm(trm);
    if (tmp != null) {
      return tmp;
    }

    throw new IllegalArgumentException("This is not a Instr: " + trm);
  }

  public nl.uva.science.pico.stacklanguage.types.LabelInstrList LabelInstrListFromTerm(aterm.ATerm trm) {
     if (trm instanceof aterm.ATermList) {
        aterm.ATermList list = ((aterm.ATermList) trm).reverse();
        nl.uva.science.pico.stacklanguage.types.LabelInstrList result = makeLabelInstrList();
        for (; !list.isEmpty(); list = list.getNext()) {
           nl.uva.science.pico.stacklanguage.types.LabelInstr elem = LabelInstrFromTerm(list.getFirst());
            result = makeLabelInstrList(elem, result);
        }
        return result;
     }
     throw new RuntimeException("This is not a LabelInstrList: " + trm);
  }

/*genTypeFromMethods*/
  public nl.uva.science.pico.stacklanguage.types.InstrList InstrListFromString(String str) {
    return InstrListFromTerm(factory.parse(str));
  }

  public nl.uva.science.pico.stacklanguage.types.InstrList InstrListFromFile(java.io.InputStream stream) throws java.io.IOException {
    return InstrListFromTerm(factory.readFromFile(stream));
  }

  public nl.uva.science.pico.stacklanguage.types.LabelInstr LabelInstrFromString(String str) {
    return LabelInstrFromTerm(factory.parse(str));
  }

  public nl.uva.science.pico.stacklanguage.types.LabelInstr LabelInstrFromFile(java.io.InputStream stream) throws java.io.IOException {
    return LabelInstrFromTerm(factory.readFromFile(stream));
  }

  public nl.uva.science.pico.stacklanguage.types.Instr InstrFromString(String str) {
    return InstrFromTerm(factory.parse(str));
  }

  public nl.uva.science.pico.stacklanguage.types.Instr InstrFromFile(java.io.InputStream stream) throws java.io.IOException {
    return InstrFromTerm(factory.readFromFile(stream));
  }

  public nl.uva.science.pico.stacklanguage.types.LabelInstrList LabelInstrListFromString(String str) {
    return LabelInstrListFromTerm(factory.parse(str));
  }

  public nl.uva.science.pico.stacklanguage.types.LabelInstrList LabelInstrListFromFile(java.io.InputStream stream) throws java.io.IOException {
    return LabelInstrListFromTerm(factory.readFromFile(stream));
  }

/*genForwardingAlternativeMethods*/
/*genForwardingMakeLists*/
/*genForwardingTypeFromTermMethods*/
/*TODOgenForwardingTypeFromMethods*/
  public static String charsToString(aterm.ATerm arg) {
    aterm.ATermList list = (aterm.ATermList) arg;
    StringBuffer str = new StringBuffer();

    for ( ; !list.isEmpty(); list = list.getNext()) {
      str.append((char) ((aterm.ATermInt) list.getFirst()).getInt());
    }

    return str.toString();
  }

  public static char charToByte(aterm.ATerm arg) {

      return((char) ((aterm.ATermInt) arg).getInt());
  }

  public aterm.ATerm stringToChars(String str) {
    int len = str.length();
    byte chars[] = str.getBytes();
    aterm.ATermList result = getPureFactory().makeList();

    for (int i = len - 1; i >= 0; i--) {
      result = result.insert(getPureFactory().makeInt(chars[i]));
    }

    return result;
  }

  public aterm.ATerm byteToChar(char ch) {
      return getPureFactory().makeInt(ch);
  }

}
